Lab 10: advanced tricks for loading and manipulating files Agenda * wildcard expressions * the global command * advanced meta editing # wildcards ? matches one character * matches anything, including nothing ** matches anything, including nothing, recurses into directories [abc] match 'a', 'b' or 'c' # advanced file commands :edit **/*.sh open file with wildcards :e **/*.sh open file with wildcards, short form :find **/vim.txt find file with wildcards, uses path & suffixesadd :next *.txt open files using wildcards, multiple results :arg *.txt open files using wildcards, multiple results :arg ../**/vim.txt open files using wildcards, multiple results # jump to file gf file under cursor in full screen ctrl-w, f file under cursor in split set path=[path] lookup path for :find, gf, gF, etc. set suffixesadd=[ext] auto add extension when using :find, gf, gF, etc. # backtick expansion :e `find -name 'script.sh'` find file using native command :arg `find -name 'Main.java'` find files using native command, multiple results # mutli-edits :argdo [ex-command] run ex-command on all files in the argument list :bufdo [ex-command] run ex-command on all open buffers :hide argdo invoke argdo on hidden buffers :hide bufdo invoke bufdo on hidden buffers :set hidden allow changes to hidden buffers # global :[range] g[lobal] /{pattern}/ [cmd] # syntax of the global command :g!/[regex]/[command] # invert the search result :vglobal/[regex]/[command] # invert the search result :v/[regex]/[command] # invert the search result, short form :g/[regex]/d # delete lines matching a regex :g/[regex]/m$ # move lines matching a regex :g/[regex]/s/[query]/[replacement]/g # for matching lines, run substitute :g/[regex]/ normal [keys] # send normal mode keystrokes on match # example ex-commands usable in combination with global delete delete the lines yank yank the lines copy copy the lines move move the lines substitute perform substitution on the lines normal send a sequence of normal mode keystrokes to the lines # vimgrep vimgrep /[expr]/ [files] search for files containing an expression vim /[expr]/ [files] short form vim //g **/*.txt repeat last search on all .txt files # quickfix :cnext show next result :cn show next result, short form :cprevious show previous result :cp show previous result, short form :cfirst show first result :clast show last result :copen open the quickfix menu :cclose close the quickfix menu :ccl close the quickfix menu, short form :cfdo [cmd] run the specified ex-command on all matching files :cdo [cmd] run the specified ex-command on all matching lines # help pages :help grep :help quickfix